﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace TMI85303.UI.Cov
{
    /// <summary>
    /// 当Double为最小值时，显示 --
    /// </summary>
    public class Double2Str__Cov : IValueConverter
    {
        public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double doubleVal)
            {
                return doubleVal == double.MinValue ? "--" : doubleVal.ToString(culture);
            }
            return null;
        }

        public object? ConvertBack(object? value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value as string == "--")
            {
                return double.MinValue;
            }
            // 从TextBox转换回绑定源属性
            return double.TryParse(value as string, out var number) ? number : null;
        }
    }
}
